using IrisGenerator.Common.DataTypes;
using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.DatabaseModel {
    
    
    public partial class Request {
        
        private System.Nullable<System.Guid> _reqId;
        
        private System.Nullable<System.Guid> _reqTypId;
        
        private System.Nullable<System.Guid> _tabId;
        
        private System.Nullable<System.Guid> _dbId;
        
        private System.Nullable<System.Guid> _metId;
        
        private string _reqName;
        
        private string _reqFormatedName;
        
        private string _reqExistingCode;
        
        private string _reqGeneratedCode;
        
        private System.Nullable<bool> _reqOverrideExisting;
        
        private InsertColumnsCollection _insertColumnsCollection;
        
        private OrderbyColumnsCollection _orderbyColumnsCollection;
        
        private Database _database;
        
        private Metatype _metatype;
        
        private RequestType _requestType;
        
        private Table _table;
        
        private RequestParameterCollection _requestParameterCollection;
        
        private SelectColumnsCollection _selectColumnsCollection;
        
        private UpdateColumnsCollection _updateColumnsCollection;
        
        public virtual System.Nullable<System.Guid> ReqId {
            get {
                return _reqId;
            }
            set {
                _reqId = value;
            }
        }
        
        public virtual string ReqName {
            get {
                return _reqName;
            }
            set {
                _reqName = value;
            }
        }
        
        public virtual string ReqFormatedName {
            get {
                return _reqFormatedName;
            }
            set {
                _reqFormatedName = value;
            }
        }
        
        public virtual string ReqExistingCode {
            get {
                return _reqExistingCode;
            }
            set {
                _reqExistingCode = value;
            }
        }
        
        public virtual string ReqGeneratedCode {
            get {
                return _reqGeneratedCode;
            }
            set {
                _reqGeneratedCode = value;
            }
        }
        
        public virtual System.Nullable<bool> ReqOverrideExisting {
            get {
                return _reqOverrideExisting;
            }
            set {
                _reqOverrideExisting = value;
            }
        }
        
        public virtual InsertColumnsCollection InsertColumnsCollection {
            get {
                if ((this._insertColumnsCollection == null)) {
                    _insertColumnsCollection = IrisGenerator.Common.DatabaseModel.InsertColumns.Select_INSERT_COLUMNS_By_REQ_ID(this.ReqId);
                }
                return this._insertColumnsCollection;
            }
        }
        
        public virtual OrderbyColumnsCollection OrderbyColumnsCollection {
            get {
                if ((this._orderbyColumnsCollection == null)) {
                    _orderbyColumnsCollection = IrisGenerator.Common.DatabaseModel.OrderbyColumns.Select_ORDERBY_COLUMNS_By_REQ_ID(this.ReqId);
                }
                return this._orderbyColumnsCollection;
            }
        }
        
        public virtual Database Database {
            get {
                if ((this._database == null)) {
                    this._database = IrisGenerator.Common.DatabaseModel.Database.Load(this._dbId);
                }
                return this._database;
            }
            set {
                _database = value;
            }
        }
        
        public virtual Metatype Metatype {
            get {
                if ((this._metatype == null)) {
                    this._metatype = IrisGenerator.Common.DataTypes.Metatype.Load(this._metId);
                }
                return this._metatype;
            }
            set {
                _metatype = value;
            }
        }
        
        public virtual RequestType RequestType {
            get {
                if ((this._requestType == null)) {
                    this._requestType = IrisGenerator.Common.DatabaseModel.RequestType.Load(this._reqTypId);
                }
                return this._requestType;
            }
            set {
                _requestType = value;
            }
        }
        
        public virtual Table Table {
            get {
                if ((this._table == null)) {
                    this._table = IrisGenerator.Common.DatabaseModel.Table.Load(this._tabId);
                }
                return this._table;
            }
            set {
                _table = value;
            }
        }
        
        public virtual RequestParameterCollection RequestParameterCollection {
            get {
                if ((this._requestParameterCollection == null)) {
                    _requestParameterCollection = IrisGenerator.Common.DatabaseModel.RequestParameter.Select_REQUEST_PARAMETER_By_REQ_ID(this.ReqId);
                }
                return this._requestParameterCollection;
            }
        }
        
        public virtual SelectColumnsCollection SelectColumnsCollection {
            get {
                if ((this._selectColumnsCollection == null)) {
                    _selectColumnsCollection = IrisGenerator.Common.DatabaseModel.SelectColumns.Select_SELECT_COLUMNS_By_REQ_ID(this.ReqId);
                }
                return this._selectColumnsCollection;
            }
        }
        
        public virtual UpdateColumnsCollection UpdateColumnsCollection {
            get {
                if ((this._updateColumnsCollection == null)) {
                    _updateColumnsCollection = IrisGenerator.Common.DatabaseModel.UpdateColumns.Select_UPDATE_COLUMNS_By_REQ_ID(this.ReqId);
                }
                return this._updateColumnsCollection;
            }
        }
        
        private void Clean() {
            this.ReqId = null;
            this._reqTypId = null;
            this._tabId = null;
            this._dbId = null;
            this._metId = null;
            this.ReqName = string.Empty;
            this.ReqFormatedName = string.Empty;
            this.ReqExistingCode = string.Empty;
            this.ReqGeneratedCode = string.Empty;
            this.ReqOverrideExisting = null;
            this._insertColumnsCollection = null;
            this._orderbyColumnsCollection = null;
            this.Database = null;
            this.Metatype = null;
            this.RequestType = null;
            this.Table = null;
            this._requestParameterCollection = null;
            this._selectColumnsCollection = null;
            this._updateColumnsCollection = null;
        }
        
        private void Fill(System.Data.DataRow dr) {
            this.Clean();
            if ((dr["REQ_ID"] != System.DBNull.Value)) {
                this.ReqId = ((System.Nullable<System.Guid>)(dr["REQ_ID"]));
            }
            if ((dr["REQ_TYP_ID"] != System.DBNull.Value)) {
                this._reqTypId = ((System.Nullable<System.Guid>)(dr["REQ_TYP_ID"]));
            }
            if ((dr["TAB_ID"] != System.DBNull.Value)) {
                this._tabId = ((System.Nullable<System.Guid>)(dr["TAB_ID"]));
            }
            if ((dr["DB_ID"] != System.DBNull.Value)) {
                this._dbId = ((System.Nullable<System.Guid>)(dr["DB_ID"]));
            }
            if ((dr["MET_ID"] != System.DBNull.Value)) {
                this._metId = ((System.Nullable<System.Guid>)(dr["MET_ID"]));
            }
            if ((dr["REQ_NAME"] != System.DBNull.Value)) {
                this.ReqName = ((string)(dr["REQ_NAME"]));
            }
            if ((dr["REQ_FORMATED_NAME"] != System.DBNull.Value)) {
                this.ReqFormatedName = ((string)(dr["REQ_FORMATED_NAME"]));
            }
            if ((dr["REQ_EXISTING_CODE"] != System.DBNull.Value)) {
                this.ReqExistingCode = ((string)(dr["REQ_EXISTING_CODE"]));
            }
            if ((dr["REQ_GENERATED_CODE"] != System.DBNull.Value)) {
                this.ReqGeneratedCode = ((string)(dr["REQ_GENERATED_CODE"]));
            }
            if ((dr["REQ_OVERRIDE_EXISTING"] != System.DBNull.Value)) {
                this.ReqOverrideExisting = ((System.Nullable<bool>)(dr["REQ_OVERRIDE_EXISTING"]));
            }
        }
        
        public static RequestCollection Select_REQUEST_By_DB_ID(System.Nullable<System.Guid> DB_ID) {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                System.Data.DataSet ds = dbo.Select_REQUEST_By_DB_ID(DB_ID);
                RequestCollection collection = new RequestCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Request obj = new Request();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static RequestCollection Select_REQUEST_By_MET_ID(System.Nullable<System.Guid> MET_ID) {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                System.Data.DataSet ds = dbo.Select_REQUEST_By_MET_ID(MET_ID);
                RequestCollection collection = new RequestCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Request obj = new Request();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static RequestCollection Select_REQUEST_By_REQ_TYP_ID(System.Nullable<System.Guid> REQ_TYP_ID) {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                System.Data.DataSet ds = dbo.Select_REQUEST_By_REQ_TYP_ID(REQ_TYP_ID);
                RequestCollection collection = new RequestCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Request obj = new Request();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static RequestCollection Select_REQUEST_By_TAB_ID(System.Nullable<System.Guid> TAB_ID) {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                System.Data.DataSet ds = dbo.Select_REQUEST_By_TAB_ID(TAB_ID);
                RequestCollection collection = new RequestCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Request obj = new Request();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static RequestCollection GetAll() {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                System.Data.DataSet ds = dbo.REQUEST_Select_All();
                RequestCollection collection = new RequestCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Request obj = new Request();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static Request Load(System.Nullable<System.Guid> REQ_ID) {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                System.Data.DataSet ds = dbo.REQUEST_Select_One(REQ_ID);
                Request obj = null;
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        obj = new Request();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Load() {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                System.Data.DataSet ds = dbo.REQUEST_Select_One(this.ReqId);
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Insert() {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                this.ReqId=dbo.REQUEST_Insert(this.RequestType.ReqTypId, this.Table.TabId, this._dbId, this.Metatype.MetId, 
                    this.ReqName, this.ReqFormatedName, this.ReqExistingCode, this.ReqGeneratedCode, this.ReqOverrideExisting);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Delete() {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                dbo.REQUEST_Delete(this.ReqId);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Update() {
            IrisGenerator.Dal.Request dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Request();
                dbo.REQUEST_Update(this.ReqId, this.RequestType.ReqTypId, this.Table.TabId, 
                    this._dbId, this.Metatype.MetId, this.ReqName, this.ReqFormatedName, this.ReqExistingCode, this.ReqGeneratedCode, this.ReqOverrideExisting);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
    }
}
